package dieciLuglio;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class Prova {
	public static void main(String [] args){
		Statement stat=null;
		Connection conn=null;
		ResultSet rs=null;
		String a=null;
		String prendiUtente="select statoPC from Tavolo where idTavolo=0";
		try {
			conn = getConnection();
			stat = conn.createStatement();
			rs = stat.executeQuery(prendiUtente);
			while(rs.next()){
				a=rs.getString(1);
			}
			System.out.println(a);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		finally{
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public static Connection getConnection()throws SQLException, IOException{  

		Properties props = new Properties();
		FileInputStream in = new FileInputStream("database.properties");
		props.load(in);
		in.close();

		String drivers = props.getProperty("jdbc.drivers");
		String url = props.getProperty("jdbc.url");
		String username =props.getProperty("jdbc.username");
		String password = props.getProperty("jdbc.password");

		if (drivers != null)
			System.setProperty("jdbc.drivers", drivers);

		return DriverManager.getConnection(url, username, password);
	}
}
